﻿using System;
using System.Collections.Generic;
using System.Text;

namespace efish.Framework.Common
{
    [Serializable]
    public class PageList<T> : List<T>, IPageList<T>
    {
        #region Constructor
        public PageList() : base()
        {

        }

        public PageList(int _TotalCount, int _Page, int _PageSize) : base()
        {
            this.TotalCount = _TotalCount;
            this.CurrentPage = _Page;
            this.PageSize = _PageSize;
            CountTotalPages();
        }

        #endregion

        #region IListPage members

        private int m_PageSize = 15;
        public int PageSize
        {
            get
            {
                return m_PageSize;
            }
            set
            {
                m_PageSize = value;
            }
        }

        private int m_TotalCount = 0;
        public int TotalCount
        {
            get
            {
                return m_TotalCount;
            }
            set
            {
                m_TotalCount = value;
            }
        }

        private int m_TotalPage = 1;
        public int TotalPage
        {
            get
            {
                if (!m_Is_Count)
                {
                    CountTotalPages();
                }
                return m_TotalPage;
            }
            set
            {
                m_TotalPage = value;
            }
        }

        private int m_CurrentPage = 1;
        public int CurrentPage
        {
            get
            {
                return m_CurrentPage;
            }
            set
            {
                m_CurrentPage = value;
            }
        }
        
        public void AddList(IList<T> list)
        {
            this.AddList(list);
        }

        #endregion

        #region CountTotalPages
        private bool m_Is_Count = false;
        private void CountTotalPages()
        {
            TotalPage = (TotalCount + PageSize - 1) / PageSize;
            m_Is_Count = true;
        }
        #endregion
    }

    public interface IPageList<T> : IList<T>
    {
        /// <summary>
        /// Record max count each page
        /// </summary>
        int PageSize { get; set; }

        /// <summary>
        /// Record total
        /// </summary>
        int TotalCount { get; set; }

        /// <summary>
        /// Page total
        /// </summary>
        int TotalPage { get; set; }

        /// <summary>
        /// Current page index
        /// </summary>
        int CurrentPage { get; set; }

        void AddList(IList<T> list);
    }
}
